-
Notifications
You must be signed in to change notification settings - Fork 544
More precise implode() return type #3774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
//cc @VincentLanglet since its string accessory business :) |
| } | ||
|
|
||
| $accessoryTypes = []; | ||
| $valueTypeAsString = $arrayType->getIterableValueType()->toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the actual change is here: we use toString as the implode function internally casts everything.
that way the string types detection also works for unions of strings and non-strings (e.g. 2|'a') and so we get more precise results
VincentLanglet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
b1fb846 to
fe52c9e
Compare
75c4610 to
224d41d
Compare
8e351b9 to
3098f46
Compare
| /** @param array{0: 1, 1: 'a'|'b', 3?: 'c'|'d', 4?: 'e'|'f', 5?: 'g'|'h', 6?: 'x'|'y'} $constArr */ | ||
| public function constArrays6($constArr) { | ||
| assertType("string", implode('', $constArr)); | ||
| assertType("literal-string&lowercase-string&non-falsy-string", implode('', $constArr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memo to me: Literal string is wrong here
| if (str_contains($i, 0)) { | ||
| assertType('int', $i); | ||
| } | ||
| if (str_contains($s, 0)) { | ||
| assertType('non-empty-string', $s); | ||
| } | ||
| if (str_contains($s, 1)) { | ||
| assertType('non-falsy-string', $s); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these cases depends on strict-types.. are we still fine with it?
|
Thank you! |
No description provided.